package com.novax.ex.activity.provider.controller;

import com.novax.ex.activity.open.api.IeoApi;
import com.novax.ex.activity.open.model.request.ActivityRequest;
import com.novax.ex.activity.open.model.response.IeoInfoResponse;
import com.novax.ex.activity.open.model.response.IeoResponse;
import com.novax.ex.activity.provider.service.IeoConfigService;
import com.novax.ex.common.constant.InternationalCode;
import com.novax.ex.common.results.ReturnResult;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @Description
 * @Author Hsylient
 * @Date 2022/12/06/16:14
 */
@RestController
public class IeoController extends BaseActivityController implements IeoApi {

    @Resource
    private IeoConfigService ieoConfigService;

    @Override
    public ReturnResult<List<IeoResponse>> items(String language, ActivityRequest activityRequest) {
        List<IeoResponse> allActivity = ieoConfigService.getAllActivity(activityRequest.getStatus());
        return ReturnResult.success(allActivity);
    }

    @Override
    public ReturnResult<IeoInfoResponse> detail(String token, String language, Long id) {
        IeoInfoResponse activityInfo = ieoConfigService.getActivityInfo(token, language, id);
        if (Objects.isNull(activityInfo)) {
            return ReturnResult.fail(getInternational(language, InternationalCode.QUERY_ERROR));
        }
        return ReturnResult.success(activityInfo);
    }
}
